import { Controller, Get, SetMetadata } from '@nestjs/common';
import { AppService } from './app.service';
import { RequireLogin, RequirePermission, UserInfo } from './custom.decorator';

@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}

  // aaa 接口需要登陆后才可以访问
  // 通过 LoginGuard 来进行权限验证
  @Get('aaa')
  // @SetMetadata('require-login', true)
  // @SetMetadata('require-permission', ['ddd'])
  @RequireLogin()
  @RequirePermission('ddd')
  aaa(@UserInfo('username') username: string, @UserInfo() userInfo) {
    // console.log(username); // admin
    // console.log(userInfo);

    return 'aaa';
  }

  @Get('bbb')
  bbb() {
    return 'bbb';
  }
}
